import 'package:boss/models/takeout_order_list_data.dart';
import 'package:boss/provider/takeout_process_provider.dart';
import 'package:boss/ui/page/commodity/categories/modal/changePriceAlert/change_price_alert.dart';
import 'package:boss/ui/page/takeoutManagement/constant/takeout_status.dart';
import 'package:boss/ui/page/takeoutManagement/page/takeoutProcess/modal/refund_modal.dart';
import 'package:boss/ui/widget/button/outline_radius_button.dart';
import 'package:boss/ui/widget/button/radius_button.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class TakePickupButtonGroup extends StatelessWidget {
  final TakeoutOrderItem data;

  const TakePickupButtonGroup({Key key, this.data}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> children = [
      OutlineRadiusButton(
        title: '退款',
        onTap: () async {
          showRefundModal(context, data: data);
        },
      )
    ];

    if (data.takeOutStatus == TakeoutStatus.RECEIVE_ORDER) {
      children.add(RadiusButton(
        title: '加小费',
        onTap: () async {
          var tip = await showChangePriceAlert(
            context,
            title: '加小费',
            hintText: '请输入小费金额',
          );
          if (tip != null) {
            var provider = Provider.of<TakeoutProcessProvider>(context, listen: false,);
            provider.tip(data, tip);
          }
        },
      ));
    }

    if ([TakeoutStatus.RIDER_TO_STORE, TakeoutStatus.RIDER_GET_PACKAGE].contains(data.takeOutStatus)) {
      children.add(RadiusButton(
        title: '取消配送',
        onTap: () {
          var provider = Provider.of<TakeoutProcessProvider>(
            context,
            listen: false,
          );
          provider.cancelDelivery(data.takeOutId);
        },
      ));
    }

    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      children: children,
    );
  }
}
